import { Qrcode } from './qrcode.entity'
import { Card } from '../../card/card.entity'
import { Car } from '../../car.entity'
import { Shop } from '../../shop/shop.entity'
import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  OneToMany,
  OneToOne,
  ManyToMany,
  ManyToOne
} from 'typeorm'

// 会员
import { ShopOrder } from '../../shop/shop-order.entity'
import { MemberAddress } from './member-address.entity'
import { Account } from '../../account'
@Entity()
export class Member {
  @PrimaryGeneratedColumn()
  id: number

  @Column({
    comment: 'openid',
    unique: true
  })
  openid: string

  @Column({
    comment: '昵称'
  })
  nickname: string

  @Column({
    comment: '姓名'
  })
  realname: string

  @Column({
    comment: '头像'
  })
  avatar: string

  @Column({
    comment: '电话'
  })
  mobile: string

  @Column({
    comment: '密码'
  })
  password: string

  /**
   * 一个会员有多个订单
   */
  @OneToMany(type => ShopOrder, order => order.member)
  orders: ShopOrder[]

  /**
   * 一个会员有多个店铺
   */
  @OneToMany(type => Shop, shop => shop.member)
  shops: Shop[]

  /**
   * 一个会员有多个汽车
   */
  @OneToMany(type => Car, car => car.member)
  cars: Car[]

  @OneToMany(type => Account, account => account.owner)
  accounts: Account[]

  @OneToMany(type => MemberAddress, address => address.member)
  addresses: MemberAddress[]

  // 多个会员可以有一个会员卡
  @OneToMany(type => Card, card => card.members)
  card: Card

  @ManyToOne(type => Account, account => account.members)
  account: Account

  @OneToOne(type => Qrcode, qrcode => qrcode.member)
  qrcode: Qrcode
}
